package com.lab.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;

import com.lab.dao.ScoreDao;
import com.lab.po.PageBean;
import com.lab.po.Score;
import com.lab.po.Student;
import com.lab.util.MySqlSessionFactory;

public class ScoreDaoImpl implements ScoreDao{

	
	//学生选择课程
	@Override
	public int choiceCourse(Map map) {
		SqlSession session=null;
		int i=0;
		try {
			session=MySqlSessionFactory.getSqlSession();
			i=session.insert("ScoreXml.choiceCourse",map);
			session.commit();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(session!=null){
				session.close();
			}
		}		
		return i;
	}

	//查询学生课程成绩
	@Override
	public List<Score> queryStuScore(int stId) {
		SqlSession session=null;
		List<Score> scoList=null;
		try {
			session=MySqlSessionFactory.getSqlSession();
			scoList=session.selectList("ScoreXml.queryStuScore",stId);
			session.commit();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(session!=null){
				session.close();
			}
		}
		return scoList;
	}

	//录入课程成绩
	@Override
	public int updateScore(Map map) {
		int i=0;
		SqlSession session=null;
		try {
			session=MySqlSessionFactory.getSqlSession();		
			i = session.update("ScoreXml.updateScore",map);
			session.commit();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(session!=null){
				session.close();
			}
		}
		return i;
	}

	
	//删除学生时同时删除所选课程和成绩
	@Override
	public int deleteScore(int stId) {
		int i = 0;
		SqlSession session=null;
		try {
			session=MySqlSessionFactory.getSqlSession();
			i=session.delete("ScoreXml.deleteScore", stId);
			session.commit();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			if(session!=null){
				session.close();
			}
		}
		return i;
	}
	
	
	
	

}
